#include <stdio.h>
#include <string.h>

void inverse1(const char arr[])
{
    int len = strlen(arr);
    char res_arr[11];
    int ret = 0;
    while (len >= 0)
    {
        // printf("%c", arr[length-1]);
        res_arr[ret] = arr[len - 1];
        ret++;
        len--;
    }
    len = strlen(arr);
    for (int i = 0; i < len; i++)
    {
        printf("%c", res_arr[i]);
    }
}

void inverse2(char arr[])
{
    int length = strlen(arr);
    int left = 0;
    int right = length - 1;
    while (left <= right)
    {
        char a = arr[left];
        char b = arr[right];
        a = a ^ b;
        b = a ^ b;
        a = a ^ b;
        arr[left] = a;
        arr[right] = b;
        left++;
        right--;
    }
    for (int i = 0; i < length; i++)
    {
        printf("%c", arr[i]);
    }
    putchar('\n');
}

void delete_space(char arr[])
{
    int length = strlen(arr);
    int index = 0;
    int strIndex = 0;
    while (index <= length)
    {
        char charater = arr[index];
        if (charater == ' ')
        {
            index++;
            continue;
        }
        arr[strIndex] = charater;
        index++;
        strIndex++;
    }
    //arr[strIndex]='\0';

    for (int i = 0; i < strlen(arr); i++)
    {
        printf("%c", arr[i]);
    }
    putchar('\n');
}

int main(int argc, char const *argv[])
{
    char str1[100] = "hello world";
#if 0
    inverse1(str1);
#endif
#if 0
    inverse2(str1);
#endif
    char str2[] = "how are you!";
    delete_space(str2);

    return 0;
}
